<template>
  <!-- 标签页 -->
  <div id="pageTag" v-if="isShow">
    <el-tabs v-model="editableTabsValue2" type="card" @tab-remove="removeTab">
        <el-tab-pane name="/"><div slot="label">{{$t('navbar.home')}}</div></el-tab-pane>
        <!-- <el-tab-pane v-for="item in editableTabs2" :key="item.name" closable :label="item.title" :name="item.name" >
        </el-tab-pane> -->
    </el-tabs>
  </div>
</template>
<script>
import {mapState} from 'vuex'
export default {
  name: "pageTag",
  props: {},
  data() {
    return {
      editableTabsValue2: this.$route.path,
        editableTabs2: [{
          title: 'Tab 1',
          name: '1',
          content: 'Tab 1 content'
        }, {
          title: 'Tab 2',
          name: '2',
          content: 'Tab 2 content'
        }],
        tabIndex: 2
    }
  },
  computed: {
    ...mapState(['isShow'])
  },
  methods: {
    addTab() {
        let newTabName = ++this.tabIndex + '';
        this.editableTabs2.push({
          title: 'New Tab',
          name: newTabName,
          content: 'New Tab content'
        });
        this.editableTabsValue2 = newTabName;
      },
    removeTab(targetName) {
        let tabs = this.editableTabs2;
        let activeName = this.editableTabsValue2;
        if (activeName === targetName) {
          tabs.forEach((tab, index) => {
            if (tab.name === targetName) {
              let nextTab = tabs[index + 1] || tabs[index - 1];
              if (nextTab) {
                activeName = nextTab.name;
              }
            }
          });
        }
        
        this.editableTabsValue2 = activeName;
        this.editableTabs2 = tabs.filter(tab => tab.name !== targetName);
      }
  },
  created() {},
  mounted() {},
};
</script>
<style lang="scss" scoped>
#pageTag {
  width: 100%;
  margin-top: 1px;
  margin-bottom: 1px;
  height: 41px;
  border-bottom: 1px solid #EBEEF5;
}
</style>
